﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.WebNemo.Business.Groups;

namespace blackhouse.WebNemo.Web.Controls {
    internal class EditControllerColumnHelper {

        #region Fields

        private bool isVirtualized;
        private VirtualColumn virtualColumn;
        private GroupColumn column;
        private List<GroupColumn> refColumns;

        #endregion

        #region Properties

        public string Name {
            get { return this.isVirtualized ? this.virtualColumn.ColumnName : this.column.ColumnName; }
        }

        public bool AllowNull {
            get { return this.isVirtualized ? this.refColumns.All(gc=>gc.AllowNull) : this.column.AllowNull; }
        }
        
        public int ColumnId {
            get { return this.isVirtualized ? this.virtualColumn.VirtualId : this.column.ColumnId; }
        }
        public string CustomEditControl {
            get { return this.isVirtualized ? this.virtualColumn.EditControl : this.column.CustomEditControl; }
        }
        
        #endregion

        #region Constructors

        public EditControllerColumnHelper(VirtualColumn column, List<GroupColumn> refColumns) {
            this.isVirtualized = true;
            this.virtualColumn = column;
            this.refColumns = refColumns;
        }

        public EditControllerColumnHelper(GroupColumn column) {
            this.isVirtualized = false;
            this.column = column;
        }

        #endregion

        #region Methods

        public string GetCustomEditControlConfiguration() {
            if (!this.isVirtualized)
                return this.column.GetCustomEditControlConfiguration();
            else
                return String.Empty;
        }

        #endregion

    }
}